<?php


namespace app\index\controller;

use app\index\model\Chat as ChatModel;  //引入model.
class Chat extends Base
{
    public function get(){
        $user = new ChatModel();
        $data=$this->request->param();
        $d= $user ->where(function ($query) use ($data) {
                $query->where('get_u_id', $data['get_u_id'])->where('send_u_id', $data['send_u_id']);
            })->whereOr(function ($query) use ($data) {
                $query->where('send_u_id',$data['get_u_id'])->where('get_u_id', $data['send_u_id']);
            })->order('cTime desc')
            ->page($data['page'])
            ->limit(10)
            ->select();
        return $d;
    }
    public function count(){
        $user = new ChatModel();
        $data=$this->request->param();
        $d= $user ->where(function ($query) use ($data) {
            $query->where('get_u_id', $data['get_u_id'])->where('send_u_id', $data['send_u_id'])
                ->where('isread',$data['isread']);
        })->order('cTime desc')
            ->count();
        return $d;
    }
    public function update()
    {
        $data = $this->request->param();
        $res = new ChatModel();
        return $res->updateModel($data);
    }
    public function delete(){
        $data = $this->request->param();
        $res = new ChatModel();
        return $res->deleteModel($data);
    }
    public function save(){
        $res = new ChatModel();
        $data = $this->request->param();
        $res->saveModel($data);
    }

}